package com.yutian.selfservice.support.upload.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * 上传至本地服务器  url映射至本地文件
 * @author zuoqiwen
 * @version 1.0
 * @date 2021-08-10
 */
@Configuration
@ConditionalOnProperty(prefix = "document.upload",name = "storageType",havingValue = "local")
public class LocalResourceConfig extends WebMvcConfigurerAdapter {
    @Autowired
    UploadConfig.UploadProperties uploadProperties;
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(uploadProperties.getAccessUrl()+"**").addResourceLocations("file:" + uploadProperties.getRootPath());
        super.addResourceHandlers(registry);
    }


}
